package com.lzy.huijinjiazu.mvp.ui.activity;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.di.component.DaggerPaymentSuccessComponent;
import com.lzy.huijinjiazu.di.module.PaymentSuccessModule;
import com.lzy.huijinjiazu.mvp.contract.PaymentSuccessContract;
import com.lzy.huijinjiazu.mvp.presenter.PaymentSuccessPresenter;
import com.lzy.huijinjiazu.mvp.ui.adapter.GoodsAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class PaymentSuccessActivity extends BaseActivity<PaymentSuccessPresenter> implements PaymentSuccessContract.View {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.tv_total)
    TextView mTvTotal;
    @BindView(R.id.rv_list)
    RecyclerView mRvList;
    private GoodsAdapter mAdapter;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerPaymentSuccessComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .paymentSuccessModule(new PaymentSuccessModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_payment_success; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mTvTotal.setText(Html.fromHtml(ArmsUtils.getString(this, R.string.total_money, "2000", "200")));
        initRecyclerView();
        initData();
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.statusBarColor(R.color.black).init();
        mImmersionBar.setTitleBarMarginTop(this, mToolbar);
    }

    private void initRecyclerView() {
        ArmsUtils.configRecyclerView(mRvList, new GridLayoutManager(this, 2) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        mRvList.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
                super.getItemOffsets(outRect, itemPosition, parent);
                outRect.right = (itemPosition + 1) % 2 == 0 ? 0 : ArmsUtils.dip2px(PaymentSuccessActivity.this, 2.5f);
                outRect.left = (itemPosition + 1) % 2 == 0 ? ArmsUtils.dip2px(PaymentSuccessActivity.this, 2.5f) : 0;
                outRect.bottom = ArmsUtils.dip2px(PaymentSuccessActivity.this, 5);
            }
        });
        mAdapter = new GoodsAdapter();
        mRvList.setAdapter(mAdapter);
    }

    private void initData() {
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            data.add("");
        }
        mAdapter.setNewData(data);
    }


}
